﻿/*
*┌─────────────────────────────────┐
*│　描   述：提现的方法
*│　类   名：GiveMoney.cs 
*│　创  建  人：DD
*│　创建时间：
*│　Copyright(C) 2020 by DD
*└─────────────────────────────────┘
*┌─────────────────────────────────┐
*│　修  改  人：
*│　创建日期：
*└─────────────────────────────────┘
*/
using Assets.Scripts.GameManager;
using UnityEngine.UI;

using UnityEngine;

namespace DD{
	public class GiveMoney:MonoBehaviour
	{
        
        public Text showMoney;

        public static float giveMoney;

        private void Start( )
        {
            //DD 加钱
            //GM.GetInstance().Diamond总钱数
            float moneyCount = PlayerPrefs.GetFloat("Money");
            //Debug.LogError ( moneyCount );

            #region 给钱算法

            if ( moneyCount < 5 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 1f , 4f ).ToString ( "f2" ) );
            }
            else if ( moneyCount < 10 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 2f , 5f ).ToString ( "f2" ) );
            }
            else if ( moneyCount < 15 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 1f , 2f ).ToString ( "f2" ) );
            }
            else if ( moneyCount < 20 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 0.3f , 1.5f ).ToString ( "f2" ) );
            }
            else if ( moneyCount < 30 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 0.5f , 1f ).ToString ( "f2" ) );
            }
            else if ( moneyCount < 40 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 0.09f , 0.5f ).ToString ( "f2" ) );
            }
            else if ( moneyCount < 60 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 0.05f , 0.1f ).ToString ( "f2" ) );
            }
            else if ( moneyCount < 80 )
            {
                giveMoney = float.Parse ( UnityEngine.Random.Range ( 0.03f , 0.05f ).ToString ( "f2" ) );
            }
            else
            {
                giveMoney = 0.01f;
            }

            showMoney.text = "$" + giveMoney.ToString ( "#0.00" );
            #endregion
        }
        //存钱
        public void SaveMoney( )
        {
            int tempDollar =Mathf.FloorToInt( PlayerPrefs.GetFloat("Money"));
            int count = tempDollar-(tempDollar%5);
            Event.Instance.Track ( "钱数:" + count );
            //GM.GetInstance ().AddDiamond ( 0 , true );
            //这是加钱的方法
            //GM.GetInstance ().MyAddDiamond ( giveMoney , true );
            InitializeAD.Instance.adType = AdType.MONEY;
            Debug.Log ( "存钱" );
            InitializeAD.Instance.showVideo ();
        }
        //跳过
        public void Skip( )
        {
            Time.timeScale = 1;
        }
    }
}